//var _baseUrl = 'http://www.cxzly.com/';
//var baseUrl_sb = 'http://www.cxzly.com/';
   var _baseUrl = 'http://192.168.1.57:1233/';
   var baseUrl_sb = 'http://192.168.1.57:1233/';
// var _baseUrl = 'http://www.citygo.lo/';
// var baseUrl_sb = 'http://www.citygo.lo/';
function myAjax(api, method, data, myfunction) {
	var	token = getApiToken(api),
		url = _baseUrl + api;
	data.api_token = token;
	console.log(api+'--'+token);
	mui.ajax(url, {
		type: method,
		data: data,
		timeout: 10000,
		success: myfunction,
		error:function(type){
			console.log(api+'--'+type.status);
			if(type.status == 401){
				mui.toast('账号异常，请重新登录!');
				plus.nativeUI.closeWaiting();
				mui.openWindow({
					url:'/pages/login/login.html',
				});
				setTimeout(function(){
					var main = plus.webview.getWebviewById('index_menu.html');
					if(main){
						plus.webview.close(main);
					}
					plus.nativeUI.closeWaiting();
				},300)
			}
			mui.toast('网络错误！');
			plus.nativeUI.closeWaiting();
		}
	});
}


function myAnotherAjax(api, method, data, myfunction) {
	var	token = getApiToken(api),
		url = baseUrl_sb + api;
	data.api_token = token;
	mui.ajax(url, {
		type: method,
		data: data,
		success: myfunction
	});
}

function getApiToken(api) {
	var date = new Date(),
		year = date.getFullYear(),
		month = (date.getMonth() + 1).toString(),
		day = date.getDate().toString();
	month = checkDate(month);
	day = checkDate(day);
	var _date = year + '/' + month + '/' + day;
	var model, controller, action;
	var token = 'ct!zi&uhg9&b$*nw4m9^a51e%ps^*m7h';
	var array = api.split("/");
	model = array[0].toLowerCase();
	action = array[2].toLowerCase();
	var apiToken = hex_md5(model + action + _date + token);
	return apiToken;
}

function checkDate(date) {
	if(date.length == 1) {
		date = '0' + date;
	}
	return date;
}